/**
 * 用户所持有的书
 */
//初始化
$(document).ready(function(){
	initRequest();
});
function initRequest(){
    $.post("userbookList","",function(result){
    	putonTable(result);
    });
};
//放在表格上
function putonTable(list){
    var table = $('#content');
    $("#content tr:not(:first)").remove();
    for ( var k in list){
        var tr = $("<tr></tr>");
	tr.appendTo(table);
        var td;
        td = $("<td>" + list[k]['bookid'] + "</td>");
        td.appendTo(tr);
        td = $("<td>" + list[k]['bookname'] + "</td>");
        td.appendTo(tr);
        td = $("<td>" + list[k]['publisher'] + "</td>");
        td.appendTo(tr);
        td = $("<td>" + list[k]['date'] + "</td>");
        td.appendTo(tr);
        //这段代码无效
        td = $("<td>" +"否"+ "</td>");
        td.appendTo(tr); 
        td = $("<td><button id=btn"+list[k]['bookid'] +">还书</button>");
        td.appendTo(tr);
        addEvent("btn"+list[k]['bookid'],list[k]['bookid']);//此处添加事件
        
    }
}
//添加事件
function addEvent(buttonId,bookid){
	 $('#'+buttonId).bind("click",function(){
	        $.post("returnBook","bookid="+bookid,function(result){
	            var msg ;
	            if(result === "success")
	                msg = "书本已还";
	            pop_init("系统信息",msg);  
	            $('#pop_div').fadeIn(400);
			    setTimeout(function() {
			    	window.location.reload();
			    	}, 2000);
	        		});
	    });
}
//添加通知框
function pop_init(title,content) {  
    //取当前浏览器窗口大小  
    var windowWidth=document.body.clientWidth; 
    var windowHeight=document.body.clientHeight; 
    //弹窗的大小  
    var weight=250;  
    var height=132;  
    $("body").append(  
   "<div id='pop_div'style='display:none;position:absolute;border:1px solid #e0e0e0;z-index:99;width:"+weight+"px;height:"+height+"px;top:"+(windowHeight-height-132)+"px;left:"+(windowWidth-weight)+"px'>"+  
        "<div style='line-height:32px;background:#F4A460;border-bottom:1px solid #e0e0e0;font-size:14px;padding:0 0 0 10px;'>" +  
            "<div style='float:left;'><b>"+title+"</b></div><div style='float:right;cursor:pointer;'><b onclick='pop_close()'>×</b></div>" +  
            "<div style='clear:both'></div>"+  
        "</div>" +  
        "<div id='content' style='background:#EED8AE;height:100px;'>" +  
             content+  
        "</div>"+  
    "</div>" 
    );  
}  
function pop_close(){  
    $('#pop_div').fadeOut(400);  
}  